<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="/wk3un7/backstage/lib/css/layui.css" />
	</head>
	<body>
		<form class="layui-form" style="margin: 58px;">
		<div class="layui-form-item" hidden="hidden">
					<label class="layui-form-label">编号:</label>
					<div class="layui-input-inline" style="width:350px;">
						<input type="text" id="ssId" name="ssId" class="layui-input" readonly="true">
					</div>
				</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>图片地址</label>
				<div class="layui-input-inline">
					<button type="button" class="layui-btn" id="test1">
				  			<i class="layui-icon">&#xe67c;</i>上传图片
					</button>
					<img id="imgFace" style="width: 120px;" src="" >
					<input type="hidden" id="imgURL" name="imgURL" required lay-verify="required" placeholder="图片地址" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>图片名称</label>
				<div class="layui-input-inline">
					<input type="text" name="ImgName" id="ImgName" required lay-verify="required" placeholder="图片名称" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span style="color: red;">*</span>跳转地址</label>
				<div class="layui-input-inline">
					<input type="text" name="ImgUrl" id="ImgUrl" required lay-verify="required" placeholder="跳转地址" autocomplete="off" class="layui-input">
				</div>
			</div>
			 
		
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
				</div>
			</div>
		</form>
		<script src="/wk3un7/backstage/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script>
			//加载了layui的form模块
			layui.use(['form','upload'], function() {
				var form = layui.form;
				var $ = layui.jquery; //引入jquery
				 var layer = layui.layer;
				 var upload = layui.upload;
				//监听提交
				  //执行实例
						  var uploadInst = upload.render({
						    elem: '#test1' //绑定元素
						    ,url: '/wk3un7/slideshowServlet?method=upload' //上传接口
						    ,done: function(res){
						      $("#imgURL").val('../upload/'+res.data);
						      $("#imgFace").attr('src','../upload/'+res.data);
						      
						    	//上传完毕回调
						    }
						    ,error: function(){
						      //请求异常回调
						    }
						  });
				form.on('submit(formDemo)', function(data) {
					var d = data.field; //表单中的数据，定义一个对象来接收
					//通过ajax向数据库提交数据了
					d.method="update";
					console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
					var url= ' /wk3un7/slideshowServlet';//请求服务器的连接地址
					//确保数据没有问题就进行ajax提交了
					$.post(url, d,
						function(data) {
							if(data.cont>0){
								console.log('添加成功');
								layer.msg('修改成功');
								var index=parent.layer.getFrameIndex(window.name); //获取当前窗口的name
             					 parent.layer.close(index);		//关闭窗口
							}
						}, "json");
					return false;
				});
			});
		</script>
	</body>
</html>
